package net.sx.minemodule.mvp.activities;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.homegoods.aroutercomment.ARouterPath;
import com.kedll.library.base.MyBaseFragmentActivity;
import com.kedll.library.util.ToastUtil;

import net.sx.minemodule.R;
import net.sx.minemodule.databinding.MineActivityMineWithDrawBinding;
import net.sx.minemodule.mvp.presenters.MineWithDrawPresenter;
import net.sx.minemodule.mvp.views.MineWithDrawView;

/**
 * 提现界面
 *
 * @author 11470
 */
@Route(path = ARouterPath.PATH_MINE_PACKAGE_WITH_DRAW)
public class MineWithDrawActivity extends MyBaseFragmentActivity<MineActivityMineWithDrawBinding, MineWithDrawPresenter> implements MineWithDrawView, View.OnClickListener {
    private String balance;
    private String payType;

    @Override

    protected int getLayout() {
        return R.layout.mine_activity_mine_with_draw;
    }

    @Override
    protected void initToolBar(Bundle savedInstanceState) {
        super.initToolBar(savedInstanceState);
        setTitle("提现");
    }

    @Override
    protected void initEvent() {
        mBinding.wechatImg.setOnClickListener(this);
        mBinding.alipayImg.setOnClickListener(this);
        mBinding.bankImg.setOnClickListener(this);
        mBinding.tvOkWithDraw.setOnClickListener(v -> {
            String input = mBinding.etInputPayPackagePay.getText().toString().trim();
            if (TextUtils.isEmpty(input)) {
                ToastUtil.showToast("提现金额不能为空");
            }
            if (Integer.valueOf(input) > Integer.valueOf(balance)) {
                ToastUtil.showToast("提现金额不能大于可提现余额");
            }
            //TODO 银行卡没有
            mPresenter.toWithDraw(input, payType, "");
        });

    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        if (getIntent() != null) {
            balance = getIntent().getStringExtra("balance");
        }
        mBinding.tvMoneyWithDrawPackage.setText(balance);

    }


    @Override
    protected MineWithDrawPresenter getPresenter() {
        return new MineWithDrawPresenter(this);
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.wechat_img) {
            payType = "0";
            mBinding.wechatImg.setSelected(true);
            mBinding.alipayImg.setSelected(false);
            mBinding.bankImg.setSelected(false);
        } else if (i == R.id.alipay_img) {
            payType = "1";
            mBinding.wechatImg.setSelected(false);
            mBinding.alipayImg.setSelected(true);
            mBinding.bankImg.setSelected(false);
        } else {
            payType = "2";
            mBinding.wechatImg.setSelected(false);
            mBinding.alipayImg.setSelected(false);
            mBinding.bankImg.setSelected(true);
        }
    }
}
